/*
 * Copyright(C) 2012 Luvina Software Company
 *
 * KatakanaValidator.java, Jun 7, 2012 HaiPD
 */
package net.luvina.manageuser.validator;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

import net.luvina.manageuser.util.Message;
import net.luvina.manageuser.util.StringUtill;

/**
 * KatakanaValidator
 *
 * @author HaiPD
 *
 */
public class KatakanaValidator implements Validator {

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * javax.faces.validator.Validator#validate(javax.faces.context.FacesContext
	 * , javax.faces.component.UIComponent, java.lang.Object)
	 */
	@Override
	public void validate(FacesContext context, UIComponent component,
			Object object) throws ValidatorException {
		String labelField = (String) component.getAttributes().get("label");
		if (!StringUtill.isKatakana(object.toString())) {
			FacesMessage msg_er007 = new FacesMessage("「" + labelField + "」 "
					+ Message.getString("ER009"));
			msg_er007.setSeverity(FacesMessage.SEVERITY_ERROR);
			throw new ValidatorException(msg_er007);
		}

	}

}
